<template>
    <BPTable ref='tableRef' align='center' row-key='id' :columns='columns' :api='pageApi'>
        <template #$action="{record}">
            <a download :href="staticurl + record.url">下载</a>
        </template>
    </BPTable>
    


</template>

<script lang='ts' setup>
    import { pageApi, deleteApi } from '@/api/ExportTask'
    import { ref } from 'vue'
    import { parseTime } from '@/utils'
    import { useI18nStore } from '@/store/i18n'
import { message } from 'ant-design-vue'

    const staticurl = import.meta.env.B_NET_STATIC_URL



    const i18n = useI18nStore()
    const tableRef = ref()

    const types = {1 : '后台操作日志', 2 : '门户登录日志'}
    const status = {0 : '生成中', 1 : '已生成'}
    

    const columns = ref<Column[]>([
        {
            title : "来源",
            dataIndex : 'type',
            align : 'center',
            inSearch : true,
            type : 'select',
            options : types,
            customRender({record}) {
                return types[record.type]
            }
        },

        {
            title : "状态",
            dataIndex : 'status',
            align : 'center',
            inSearch : true,
            type : 'select',
            options : status,
            customRender({record}) {
                return status[record.status]
            }
        },

        {
            title : "导出时间",
            dataIndex : 'createTime',
            align : 'center',
            customRender({record}) {
                return parseTime(record.createTime)
            }
        },

        {
            title : i18n.t('operation'),
            dataIndex : '$action',
            align : 'center',

            $delete : async(row) => {
                const res = await deleteApi(row.id)
                if(res.success) {
                    tableRef.value.load()
                    message.success(i18n.t('deleteSuccess'))
                }else {
                    message.error(res.msg)
                }
            }
        }

    ])
</script>